Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const double HEALTH_PLAN=18.75;
const double FED_TAX=0.22;
const double DEPENDENT_COST= 7.35;
void employeeinfo(char name[][30],unsigned int hours[7], float &rate,int &dependents, char &healthplan);
int calculatehours(unsigned int hours[7]);
float calculategross(unsigned int hours,float &rate);
float calculatedfedtax(float grosspay);
float calculatehealth(char healthplan,int dependents);
float calculatefica(float grosspay);
void bubblename(char name[][30], int counter);
float calculateNetpay(float fedtax,float fica,char healthplan,float grosspay);
void output(float totaldata[][6],char name [][30]);
int main()
{
char name[20][30],choice,answer;
unsigned int hours[7];
float rate,totaldata[20][6];
int dependents,count = 0;
char healthplan;
int hoursworked,totalhours =0;
float gross,fedtax,fica,netpay;
cout<<"Hello and Welcome to 4DaLulz inc. Payroll computation system."<<endl;
cout<<"You will need employee information such as name,hours, and payrate"<<endl;
cout<<"\nWould you like to continue? ( Y or N ) \n";
cin>>choice;
cin.ignore(1);
switch(choice)
{
case 'Y':
case 'y':
do
{
employeeinfo(name,hours,rate,dependents,healthplan);
hoursworked=calculatehours(hours);
totalhours+=hoursworked;
gross=calculategross(hoursworked,rate);
fedtax=calculatedfedtax(gross);
fica=calculatefica(gross);
netpay=calculateNetpay(gross,fedtax,fica,healthplan);
totaldata[count][0]=hoursworked;
totaldata[count][1]=totalhours;
totaldata[count][2]=gross;
totaldata[count][3]=fedtax;
totaldata[count][4]=fica;
totaldata[count][5]=netpay;
cout<<"Are there more employees? (Y or N) \n";
cin>>answer;
cin.ignore(1);
if(toupper(answer) != 'Y')
break;
}while(choice=='Y'||choice=='y');
break;
}
output(totaldata,name);
return 0;
}
void output(float totaldata[][6],char name [][30])
{
// i can't seem to make the functions, and name data appear on the screen
// supposed to look something like
Total FICA
// Name Hours Tax // etc etc...// can't get the cout right...=(
[names] [hours] [fica]
}
void swapstrings(char a[], char b[], int length)
{
char c;
for (int i = 0; i < length; i++)
{
c = a[i];
a[i] = b[i];
b[i] = c;
}
}
//void bubblehours(unsigned int hours[7],int counter)
//{
// for(int i=1;i<counter;i++)
// for(int j=0;j<counter;j++)
// if(hours[i]>hours[j])
// swap(hours[i],hours[j]);
//}
void bubblename(char name[][30], int counter, float totaldata[][6])
{
for(int i=1;i<counter;i++)
{
for(int j=0;j<counter-i;j++)
{
if(strcmp(name[i], name[j]) > 0)
{ swapstrings(name[i], name[j],30);
for(int u=0;u<7;u++)
{
swap(totaldata[i][u],totaldata[j][u]);
}
//
}
}
}
}
void employeeinfo(char name[][30],unsigned int hours[7], float &rate,int &dependents, char &healthplan)
{
int counter = 0;
cout<<"\nEmployee's Name: \n";
cin.getline(name[counter],30,'\n');
cin.clear();
cout<<"Hours: \n";
for(int h=0;h<7;h++)
cin>>hours[h];
cout<<"Rate: \n";
cin>>rate;
cout<<"Dependents: \n";
cin>>dependents;
if(dependents<=0)
{
cout<<"You count as a dependent minimum is 1. \n";
cin>>dependents;
}
cout<<"Health Plan (Y or N)? \n";
cin>>healthplan;
}
float calculategross(unsigned int hours,float &rate)
{
if(hours>40)
return(hours-40)*1.5f*rate+40*rate;
return hours * rate;
}
int calculatehours(unsigned int hours[])
{
int hourstotal=0;
for(int h=0;h<7;h++)
hourstotal+=hours[h];
return hourstotal;
}
float calculatedfedtax(float grosspay)
{
if(grosspay>300)
return(grosspay-300)*FED_TAX;
return 0;
}
float calculatehealth(char healthplan,int dependents)
{
if(toupper(healthplan)!='Y')
return 0;
else
return HEALTH_PLAN+DEPENDENT_COST*(dependents-1);
}
float calculatefica(float grosspay)
{
float fica;
fica=grosspay*.085f;
if(fica<45)
return 45;
return fica;
}
float calculateNetpay(float fedtax,float fica,char healthplan,float grosspay)
{
double netPay;
if(healthplan=='Y'||healthplan=='y')
{
netPay=grosspay-fedtax-fica-HEALTH_PLAN;
}
else
{
netPay=grosspay-fedtax-fica;
}
return netPay;
}